
package com.kgajowy.expressions;

import com.kgajowy.ast.Tree;

import edu.pjwstk.jps.visitor.ASTVisitor;

public class Expression extends Tree {

    private String mExpression;

    @SuppressWarnings("unused")
    private Expression() {
    };

    protected Expression(String expr) {
        this.setExpression(expr);
    }

    protected Expression(Expression unary) {
        this.setLeft(unary);
        this.setRight(null);
        unary.setRoot(this);
        this.setExpression("");
    }

    protected Expression(Expression leftBinary, Expression rightBinary) {
        this.setLeft(leftBinary);
        this.setRight(rightBinary);
        if ( leftBinary != null) leftBinary.setRoot(this);
        if ( rightBinary != null) rightBinary.setRoot(this);
        this.setExpression("");
    }

    @Override
    public void accept(ASTVisitor visitor) {
        super.accept(visitor);
    }

    public String getExpression() {
        return mExpression;
    }

    public void setExpression(String expression) {
        mExpression = expression;
    }

    public void print(String sep) {
        System.out.println(sep + this.getExpression());
        if (this.getLeft() != null) this.getLeft().print(sep + "\t");
        if (this.getRight() != null) this.getRight().print(sep + "\t");
    }

}
